package com.lz.controller.fsh;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lz.entity.Car;
import com.lz.entity.Customer;
import com.lz.entity.Employee;
import com.lz.repository.fsh.vo.InsuranceSheetVo;
import com.lz.service.fsh.InsuranceSheetService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.lz.entity.InsuranceSheet;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring/applicationContext.xml"})
@Controller
public class Test01 {
	
	
@Autowired
private InsuranceSheetService insuranceSheetService;

@Test
public void test01(){
	
	List <InsuranceSheetVo>list=insuranceSheetService.getAlllist();
	for (InsuranceSheetVo insuranceSheet : list) {
		System.out.println("222");
		System.out.println();
		System.out.println(insuranceSheet);
	}

	
}
@Test
public void addtest(){
    InsuranceSheet insuranceSheet = new InsuranceSheet();
    insuranceSheet.setInsuranceSheetState("已登记");
    insuranceSheet.setInsuranceCompany("平安");
    insuranceSheet.setHandlingFee(2.6);
    insuranceSheet.setRegistrationStatus("新建");
    //时间转换String 转date
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    String time = "2018-5-03";
    String time2= "2018-8-20";
    try {
        Date date = sf.parse(time);
        Date date2 = sf.parse(time2);
        insuranceSheet.setEffectiveTime(date);
        insuranceSheet.setInvalidTime(date2);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    //储存用户信息
    Customer customer = new Customer();
    customer.setCustomerName("张三"); //客户名
    customer.setSex('男');//性别
    customer.setCustomerCardId("123333");//身份证
    customer.setCustomerTel("222222222");//电话
    customer.setCustomerAddress("sss");//住址
    //储存车辆信息
    Car car = new Car();
    car.setVin("20");//carvin
    car.setBrand("雪弗兰");//车辆品牌
    car.setSeries("x");//车系
    car.setModel("4s");//车型

    //储存员工信息
    Employee employee= new Employee();
    employee.setEmployeeName("lisi");//员工名称

    insuranceSheetService.addInsuranceSheet(insuranceSheet,customer,car,employee);
    System.out.print("1111");

}
@Test
public void del(){

    InsuranceSheet insuranceSheet = new InsuranceSheet();
    insuranceSheet.setInsuranceSheetNo(9);
    insuranceSheetService.delInsuranceSheet(insuranceSheet);
    System.out.print("1");
}

     @Test
    public void getInsuranceSheetList2() {

        Map map = new HashMap();

        map.put("customer.customerName", "楚子航");
        map.put("insuranceCompany", "中国人寿");
        map.put("registrationStatus","新建");

        Integer rows = insuranceSheetService.rowsInsuranceSheet2(map);
        System.out.println(rows);


    }
    @Test
    public void testChange(){
    InsuranceSheetVo insuranceSheetVo=new InsuranceSheetVo();
        try {
    insuranceSheetVo.setInsuranceSheetNo(10);
    insuranceSheetVo.setCustomerName("需皮皮");
    insuranceSheetVo.setHandlingFee(Double.parseDouble("20"));
    insuranceSheetVo.setInsuranceCompany("腾讯");
    insuranceSheetVo.setRegistrationStatus("新建");
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

            insuranceSheetVo.setEffectiveTime(sf.parse("2017-08-09"));
            insuranceSheetVo.setInvalidTime(sf.parse("2018-09-20"));

        insuranceSheetService.changeins(insuranceSheetVo);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("11111");
    }


}
